(()=>{
    console.log('==== ')
    
    // 属性初始化和构造函数时可以修改 readonly 属性
    class Person {
        // 属性
        // readonly name:string  = '嘻嘻'
        readonly name:string 
        constructor(name: string='哈哈哈') {
             // 类的构造方法无法修改 readonly 属性
            this.name = name 
        }

        sayHi() {
            console.log('凯尼', this.name)
            // 类的普通方法无法修改 readonly 属性
            //  Cannot assign to 'name' because it is a read-only property.
            // this.name = '大甜甜'
        }
    }

    

    const person = new Person('小甜甜')
    console.log(person)
    console.log(person.name)
    //  Cannot assign to 'name' because it is a read-only property.
    // person.name = '大甜甜'
    console.log(person.name)

    console.log('===============')


    class Person2  {
        // constructor(readonly name: string='哈哈哈') {
        //      // 类的构造方法无法修改 readonly 属性
        //     this.name = name 
        // }

        constructor(public name: string='哈哈哈') {
        }

        // constructor(protected name: string='哈哈哈') {
        // }


        sayHi() {
            console.log('凯尼', this.name)
        }
    }

    
    const person2 = new Person2('小甜甜')
    console.log(person2)
    console.log(person2.name)
    //  Cannot assign to 'name' because it is a read-only property.
    // person.name = '大甜甜'
    console.log(person2.name)

    

})()